package traingo

import (
	"encoding/json"
	"fmt"
	"github.com/chromedp/cdproto/network"
	"github.com/sirupsen/logrus"
)

func (s *TraingoStudy) loginAjax(e *network.EventResponseReceived) {
	// 监听登录行为
	b, err := network.GetResponseBody(e.RequestID).Do(s.ctx)
	var result map[string]interface{}
	err = json.Unmarshal(b, &result)
	if err != nil {
		logrus.Error(err, "接口 c/apiPrefix/public/login 返回值不是一个json")
	}
	if result["token"] == "" {
		logrus.Debug("点击二次确认登录按钮")
	} else {
		logrus.Debug("获取到token", result["token"])
		s.token = fmt.Sprintf("%v", result["token"])
	}
}
